<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

      </a-table>
    </div>

    <erp-omc-contract-manager-final-modal ref="modalForm" @ok="modalFormOk"></erp-omc-contract-manager-final-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'
import ErpOmcContractManagerFinalModal from './modules/ErpOmcContractManagerFinalModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'

export default {
  name: 'ErpOmcContractManagerFinalList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOmcContractManagerFinalModal
  },
  props: {
    disabledButton: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      description: '合同档案管理管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '合同编号',
          align: 'center',
          dataIndex: 'htbh',
          width: 151,
          ellipsis: true
        },
        {
          title: '合同名称',
          align: 'center',
          dataIndex: 'htmc',
          width: 106,
          ellipsis: true
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'xmbh',
          width: 174,
          ellipsis: true
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'xmmc_dictText',
          width: 140,
          ellipsis: true
        },
        {
          title: '业绩归属年度',
          align: 'center',
          dataIndex: 'yjgsnd_dictText',
          width: 104,
          ellipsis: true
        },
        {
          title: '签订日期',
          align: 'center',
          dataIndex: 'qdrq',
          width: 91,
          ellipsis: true,
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '合同类型',
          align: 'center',
          dataIndex: 'htlx_dictText',
          width: 75,
          ellipsis: true
        },
        {
          title: '本次合同额(元)',
          align: 'center',
          dataIndex: 'bchte',
          width: 113,
          ellipsis: true
        },
        {
          title: '签订单位',
          align: 'center',
          dataIndex: 'qddw_dictText',
          width: 190,
          ellipsis: true
        },
        {
          title: '业主单位',
          align: 'center',
          dataIndex: 'yzdw_dictText',
          width: 75,
          ellipsis: true
        },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'jytd_dictText',
          width: 240,
          ellipsis: true
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          width: 60,
          ellipsis: true
        }
      ],
      url: {
        list: '/api/erp/omc/contractmanager/erpOmcContractManager/list',
        list0: '/api/erp/omc/contractmanager/erpOmcContractManager/list?htbh=',
        delete: '/api/erp/omc/contractmanager/erpOmcContractManager/delete',
        deleteBatch: '/api/erp/omc/contractmanager/erpOmcContractManager/deleteBatch',
        exportXlsUrl: '/api/erp/omc/contractmanager/erpOmcContractManager/exportXls',
        importExcelUrl: 'api/erp/omc/contractmanager/erpOmcContractManager/importExcel',
        queryById: '/api/erp/omc/contractmanager/erpOmcContractManagerFinal/queryById'
      },
      dictOptions: {},
      superFieldList: [],
      disableMixinCreated: true,
      colsettings: 'ErpOmcContractManagerList2:colsettings'
    }
  },
  watch: {
    $route(to, from) {
      getAction(this.url.queryById, { id: this.$route.params.id }).then(res => {
        if (res.success) {
          this.url.list = this.url.list0 + res.result.htbh
          this.loadData();
        }
      })
    }
  },
  created() {
    this.getSuperFieldList();
    getAction(this.url.queryById, { id: this.$route.params.id }).then(res => {
      if (res.success) {
        this.url.list = this.url.list0 + res.result.htbh
        this.loadData();
      }
    })
    this.initColumns();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      this.loading = true
      getAction(this.url.list, params).then(res => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          // 判断是否当前页没有数据且不为第一页
          if (this.dataSource.length == 0 && this.ipagination.current != 1) {
            this.ipagination.current = this.ipagination.current - 1
            this.loadData(this.ipagination.current - 1);
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    handleDetail: function (record) {
      const _path = this.$route.path
      if (_path.startsWith('/hmhb/') || _path.startsWith('/scy/') || _path.startsWith('/imp/') ||
        _path.startsWith('/erp/')) {
          if (record && record.isOldSystem && record.isOldSystem == '1') {
            this.$router.push({
              path: `/erp/omc/oldContractmanager/ErpOmcContractManagerListDetail/${record.id}`
            })
          } else {
            this.$router.push({
              path: `/erp/omc/contractmanager/ErpOmcContractManagerListDetail/${record.id}`
            })
          }
      } else {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '详情';
        this.$refs.modalForm.disableSubmit = true;
      }
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'handlerId', text: '经办人编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptId', text: '经办人部门ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptCode', text: '经办人部门编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'delFlag', text: '是否已删除', dictCode: '' })
      fieldList.push({ type: 'string', value: 'htbh', text: '合同编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'htlx', text: '合同类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jytd', text: '经营团队', dictCode: '' })
      fieldList.push({ type: 'string', value: 'htmc', text: '合同名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmmc', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'sfyz', text: '', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yzdw', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'qddw', text: '签订单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yzlx', text: '印章类型', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yyfs', text: '用印份数', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmcjr', text: '项目承接人', dictCode: '' })
      fieldList.push({ type: 'int', value: 'glskht', text: '关联收款合同', dictCode: '' })
      fieldList.push({ type: 'date', value: 'qdrq', text: '签订日期' })
      fieldList.push({ type: 'string', value: 'lxr', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'lxfs', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yjgsnd', text: '业绩归属年度', dictCode: '' })
      fieldList.push({ type: 'int', value: 'skhte', text: '收款合同额', dictCode: '' })
      fieldList.push({ type: 'date', value: 'fwqx', text: '服务期限' })
      fieldList.push({ type: 'string', value: 'yf', text: '乙方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bchtedx', text: '本次合同额大写', dictCode: '' })
      fieldList.push({ type: 'string', value: 'skhtedx', text: '收款合同额大写', dictCode: '' })
      fieldList.push({ type: 'string', value: 'skhtmc', text: '收款合同名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'bchte', text: '本次合同额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jf', text: '甲方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmbh', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: '' })
      fieldList.push({ type: 'int', value: 'lx', text: 'lx', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bz', text: 'bz', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yjxx', text: 'yjxx', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xgfj', text: 'xgfj', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
